package com.ruoyi.bantong.controller;

import com.ruoyi.bantong.domain.BtSlideshow;
import com.ruoyi.bantong.service.IBtSlideshowService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图Controller
 * 
 * @author laohei
 * @date 2021-01-24
 */
@RestController
@RequestMapping("/bantong/slideshow")
public class BtSlideshowController extends BaseController
{
    @Autowired
    private IBtSlideshowService btSlideshowService;

    /**
     * 查询轮播图列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:slideshow:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtSlideshow btSlideshow)
    {
        startPage();
        List<BtSlideshow> list = btSlideshowService.selectBtSlideshowList(btSlideshow);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:slideshow:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtSlideshow btSlideshow)
    {
        List<BtSlideshow> list = btSlideshowService.selectBtSlideshowList(btSlideshow);
        ExcelUtil<BtSlideshow> util = new ExcelUtil<BtSlideshow>(BtSlideshow.class);
        return util.exportExcel(list, "slideshow");
    }

    /**
     * 获取轮播图详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:slideshow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(btSlideshowService.selectBtSlideshowById(id));
    }

    /**
     * 新增轮播图
     */
    //@PreAuthorize("@ss.hasPermi('bantong:slideshow:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtSlideshow btSlideshow)
    {
        btSlideshow.setCreateBy(SecurityUtils.getUsername());
        return toAjax(btSlideshowService.insertBtSlideshow(btSlideshow));
    }

    /**
     * 修改轮播图
     */
    //@PreAuthorize("@ss.hasPermi('bantong:slideshow:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtSlideshow btSlideshow)
    {
        btSlideshow.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(btSlideshowService.updateBtSlideshow(btSlideshow));
    }

    /**
     * 删除轮播图
     */
    //@PreAuthorize("@ss.hasPermi('bantong:slideshow:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(btSlideshowService.deleteBtSlideshowByIds(ids));
    }
}
